<?php

namespace app\common\utils;

use catcher\CatchUpload;

class Upfile
{
   /**
    * 上传文件
    *
    * @param $file
    * @param int $type 1 图片，2 文件
    * @param string $path 上传路径
    */    
    public function upLoad($file, int $type = 1, string $path = '')
    {
        if ($type == 1)
        {
            $checkType = (new CatchUpload())->checkImages($file);
        }else{
            $checkType = (new CatchUpload())->checkFiles($file);
        }
        
        if ($checkType)
        {
            $data = [];
            foreach ($file as $key => $val)
            {
                $data[$key] = (new CatchUpload())->upload($val, $path);
            }
            return $data;
        }
        return false;
    }
}